package m.jclecai.com.adapter.base;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;

/**
 * Created by ZD on 2017/5/4.
 */

public abstract class BaseExpandableListViewAdapter<T extends ViewGroup> extends BaseExpandableListAdapter {

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        T view;
        if (convertView == null) {
            view = onCreateParentViewHolder(groupPosition, isExpanded, convertView, parent);
            view.setId(groupPosition);
            convertView = view;
            convertView.setTag(getGroup(groupPosition));
        } else {
            view = (T) convertView;
        }
        onBindParentViewHolder(groupPosition,isExpanded,view);
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        T view;
        if (convertView == null) {
            view = onCreateChildViewHolder(groupPosition, childPosition, isLastChild, convertView, parent);
            view.setId(childPosition);
            convertView = view;
            convertView.setTag(getChild(groupPosition,childPosition));
        } else {
            view = (T) convertView;
        }
        onBindChildViewHolder(groupPosition, childPosition, isLastChild, view);
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    //为父容器创建viewholder
    public abstract T onCreateChildViewHolder(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent);
    //为父容viewholder绑定数据
    public abstract void onBindChildViewHolder(int groupPosition, int childPosition, boolean isLastChild, T t);

    public abstract T onCreateParentViewHolder(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent);
    public abstract void onBindParentViewHolder(int groupPosition, boolean isExpanded, T t);
}
